part of 'page.dart';

class _AllPhrasalVerbPageWloc
    extends StatefulWloc<_AllPhrasalVerbPageWlocState, AllPhrasalVerbPage> {
  late final bloc.AllPhrasalVerbPageBloc _bloc;

  final _viewKey = GlobalKey();

  @override
  _AllPhrasalVerbPageWlocState get initialState {
    return _AllPhrasalVerbPageWlocStateFactory().create(
      blocState: _bloc.state,
    );
  }

  void onPhrasalVerbBaseRowPartPressed({
    required String phrasalVerbId,
  }) {
    _bloc.requestSinglePhrasalVerbBasePageOpening(
      phrasalVerbId: phrasalVerbId,
    );
  }

  void onPhrasalVerbTranslationRowPartPressed({
    required String phrasalVerbId,
  }) {
    _bloc.requestSinglePhrasalVerbTranslationPageOpening(
      phrasalVerbId: phrasalVerbId,
    );
  }

  void _onBlocStateChanged(bloc.AllPhrasalVerbPageBlocState blocState) {
    final updatedState = _AllPhrasalVerbPageWlocStateFactory().create(
      blocState: blocState,
    );

    emit(updatedState);
  }

  @override
  void initState() {
    super.initState();

    _bloc = bloc.AllPhrasalVerbPageBloc(
      learningContentBloc: core_di.sl(),
      rootNavigatorBloc: core_di.sl(),
      getInitialData: all_phrasal_verb_page_di.sl(),
      handleLearningContentOuterUpdate: all_phrasal_verb_page_di.sl(),
      handleSinglePhrasalVerbBasePageOpeningRequest: all_phrasal_verb_page_di.sl(),
      handleSinglePhrasalVerbTranslationPageOpeningRequest: all_phrasal_verb_page_di.sl(),
    );

    _bloc.stream.listen(_onBlocStateChanged);
  }

  @override
  void dispose() {
    _bloc.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Localizations.override(
      context: context,
      delegates: [
        _AllPhrasalVerbPageTranslation.delegate,
      ],
      child: _AllPhrasalVerbPageTheme(
        brightness: CoreTheme.of(context).brightness,
        child: _AllPhrasalVerbPageView(
          key: _viewKey,
          wloc: this,
        ),
      ),
    );
  }
}
